﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Dark_Dungeon
{
    static public class Debug
    {
        static List<string> Textos = new List<string>();
        static List<TextoEstatico> TextosEstaticos = new List<TextoEstatico>();

        static public void AddText(string text)
        {
            Textos.Add(text);
        }

        static public void AddStaticText(string text)
        {
            AddStaticText(text, 5000);
        }
        static public void AddStaticText(string text, UInt16 time)
        {
            TextosEstaticos.Add(new TextoEstatico(text, time));
        }

        static public void Draw(GameTime gameTime, SpriteBatch spritebatch)
        {
            int filas = 10;
            int miliseconds = gameTime.ElapsedGameTime.Milliseconds;

            spritebatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

            if(miliseconds!=0)
                spritebatch.DrawString(Resources.TerminalFont, (1000 / miliseconds).ToString() + " fps", new Vector2(960, 10), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, Config.TextLayer);

            foreach(string text in Textos)
            {
                spritebatch.DrawString(Resources.TerminalFont, text, new Vector2(10, filas), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, Config.TextLayer);
                filas+=20;
            }


            filas = 10;

            List<TextoEstatico> borrar = new List<TextoEstatico>();

            foreach (TextoEstatico text in TextosEstaticos)
            {
                if (text.time > 0)
                {
                    spritebatch.DrawString(Resources.TerminalFont, text.text, new Vector2(210, filas), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, Config.TextLayer);
                    text.time -= miliseconds;
                    filas += 20;
                }
                else
                {
                    borrar.Add(text);
                }
                
            }

            

            spritebatch.End();

            Textos.Clear();
        }

        static void RemoveStaticText(List<TextoEstatico> RemoveList)
        {
            foreach (TextoEstatico txt in RemoveList)
            {
                TextosEstaticos.Remove(txt);
            }
        }
    }

    public class TextoEstatico
    {
        public string text;
        public int time; // En milisegundos

        public TextoEstatico(string text, int time)
        {
            this.text = text;
            this.time = time;
        }
        
    }
}
